<?php

namespace app\controllers;

use app\commission\CommissionNew;
use app\models\order\Order;
use app\models\Queue;

class QueueController extends Controller
{
    // */5 * * * * /usr/bin/curl https://api.wochuang8.top/queue/index
    public function actionIndex()
    {
        $list = Queue::find()
            ->where(['status' => 0])
            ->orderBy(['id' => SORT_ASC])
            ->limit(30)
            ->all();

        if (empty($list)) {
            return '[ 已经全部完成 ]';
        }

        foreach ($list as $item) {
            // 处理奖项
            $order = Order::findOne(['id' => $item->order_id]);
            if ($order) {
                $c = new CommissionNew($order, true);
                $c->receive_performance();
            }

            $item->status = 1;
            $item->save();
        }

        return ' [ 操作完成 ]';

    }
}